package com.micai.springboot.entity;

/**
 * 描述：用户表通过实现Comparable接口实现按指定字段排序
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/5/16 15:49
 */
public class UserEntity implements Comparable<UserEntity> {

    // 用户ID
    private int id;
    // 用户名称
    private String name;
    // 用户性别
    private int sex;
    // 用户年龄
    private int age;

    public UserEntity() {
    }

    public UserEntity(int id, String name, int sex, int age) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public int compareTo(UserEntity userEntity) {
        int age = ((UserEntity) userEntity).getAge();
        // 升序
        /*return this.age-age;*/
        // 降序
        return age - this.age;
    }

    @Override
    public String toString() {
        return "UserEntity{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", sex=" + sex +
                ", age=" + age +
                '}';
    }
}
